]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
iconGrid: Cache max size of children
authorJonas Dreßler <verdre@v0yd.nl>
Tue, 23 Feb 2021 18:47:45 +0000 (19:47 +0100)
committerMarge Bot <marge-bot@gnome.org>
Wed, 3 Mar 2021 17:59:15 +0000 (17:59 +0000)
We call this._getChildrenMaxSize() from the allocate() vfunc of
IconGridLayout. Since the function is quite expensive, it slows the
layout process down a lot, so instead of re-calculating it on every
relayout, cache the max size of children.

This makes the average time spent in vfunc_allocate() of the iconGrid go
down from 2.3 ms to 1.6 ms.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>

js/ui/iconGrid.js

index 2c71c29c107613ee695b1b729772c743a506d728..12f1ac025167e2f8378751f757efcee1c7b3ddd3 100644 (file)
@@ -369,6 +369,8 @@ var IconGridLayout = GObject.registerClass({
 
         this._resolveOnIdleId = 0;
         this._iconSizeUpdateResolveCbs = [];
+
+        this._childrenMaxSize = -1;
     }
 
     _findBestIconSize() {
@@ -414,21 +416,25 @@ var IconGridLayout = GObject.registerClass({
     }
 
     _getChildrenMaxSize() {
-        let minWidth = 0;
-        let minHeight = 0;
+        if (this._childrenMaxSize === -1) {
+            let minWidth = 0;
+            let minHeight = 0;
 
-        for (const child of this._container) {
-            if (!child.visible)
-                continue;
+            for (const child of this._container) {
+                if (!child.visible)
+                    continue;
 
-            const [childMinHeight] = child.get_preferred_height(-1);
-            const [childMinWidth] = child.get_preferred_width(-1);
+                const [childMinHeight] = child.get_preferred_height(-1);
+                const [childMinWidth] = child.get_preferred_width(-1);
 
-            minWidth = Math.max(minWidth, childMinWidth);
-            minHeight = Math.max(minHeight, childMinHeight);
+                minWidth = Math.max(minWidth, childMinWidth);
+                minHeight = Math.max(minHeight, childMinHeight);
+            }
+
+            this._childrenMaxSize = Math.max(minWidth, minHeight);
         }
 
-        return Math.max(minWidth, minHeight);
+        return this._childrenMaxSize;
     }
 
     _getVisibleChildrenForPage(pageIndex) {
@@ -445,6 +451,7 @@ var IconGridLayout = GObject.registerClass({
 
         item.disconnect(itemData.destroyId);
         item.disconnect(itemData.visibleId);
+        item.disconnect(itemData.queueRelayoutId);
 
         this._items.delete(item);
     }
@@ -557,6 +564,9 @@ var IconGridLayout = GObject.registerClass({
                 else if (!this.allowIncompletePages)
                     this._fillItemVacancies(itemData.pageIndex);
             }),
+            queueRelayoutId: item.connect('queue-relayout', () => {
+                this._childrenMaxSize = -1;
+            }),
         });
 
         item.icon.setIconSize(this._iconSize);